package com.fc.test.service;

import java.util.List;
import java.util.Arrays;

import com.fc.test.model.auto.NoticeInfo;
import com.fc.test.model.auto.NoticeInfoExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.EntCollectMapper;
import com.fc.test.model.auto.EntCollect;
import com.fc.test.model.auto.EntCollectExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 * 企业收藏数据 EntCollectService
 * @Title: EntCollectService.java 
 * @Package com.fc.test.service 
 * @author DrRic_自动生成
 * @email drhyz@qq.com
 * @date 2020-07-05 17:21:13  
 **/
@Service
public class EntCollectService implements BaseService<EntCollect, EntCollectExample>{
	@Autowired
	private EntCollectMapper entCollectMapper;
	
      	   	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<EntCollect> list(Tablepar tablepar,EntCollect record){
	        EntCollectExample testExample=new EntCollectExample();
	        if(record.getEid()!=null){
				testExample.createCriteria().andEidEqualTo(record.getEid());
				testExample.setOrderByClause("id ASC");
				if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
					testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
				}
				PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
				List<EntCollect> list= entCollectMapper.selectByExample(testExample);
				PageInfo<EntCollect> pageInfo = new PageInfo<EntCollect>(list);
				return  pageInfo;
			}
		 	return new PageInfo<>();
	 }

	public PageInfo<EntCollect> listForSys(Tablepar tablepar, EntCollect record){
		EntCollectExample testExample=new EntCollectExample();
		testExample.createCriteria().andLikeQuery(record);
		testExample.setOrderByClause("eid ASC");
		if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
			testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
		}
		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
		List<EntCollect> list= entCollectMapper.selectByExample(testExample);
		PageInfo<EntCollect> pageInfo = new PageInfo<EntCollect>(list);
		return  pageInfo;
	}

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			EntCollectExample example=new EntCollectExample();
			example.createCriteria().andIdIn(stringB);
			return entCollectMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public EntCollect selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return entCollectMapper.selectByPrimaryKey(id1);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(EntCollect record) {
		return entCollectMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(EntCollect record) {
				
		record.setId(null);
		
				
		return entCollectMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(EntCollect record, EntCollectExample example) {
		
		return entCollectMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(EntCollect record, EntCollectExample example) {
		
		return entCollectMapper.updateByExample(record, example);
	}

	@Override
	public List<EntCollect> selectByExample(EntCollectExample example) {
		
		return entCollectMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(EntCollectExample example) {
		
		return entCollectMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(EntCollectExample example) {
		
		return entCollectMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param entCollect
	 * @return
	 */
	public int checkNameUnique(EntCollect entCollect){
		EntCollectExample example=new EntCollectExample();
		example.createCriteria().andCvidEqualTo(entCollect.getCvid());
		List<EntCollect> list=entCollectMapper.selectByExample(example);
		return list.size();
	}


}
